<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
  <title>后台管理系统</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="/resources/css/dpl-min.css" rel="stylesheet" type="text/css" />
  <link href="/resources/css/bui-min.css" rel="stylesheet" type="text/css" />
  <link href="/resources/css/page-min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">

    <form id="searchForm" class="form-horizontal">
        <div class="row">
            <div class="control-group span8" style="width: 220px;">
                <label class="control-label" style="width: 50px;">订单号：</label>
                <div class="controls">
                    <input type="text" class="control-text" name="no" id="no">
                </div>
            </div>
            <div class="control-group span8" style="width: 220px;">
                <label class="control-label" style="width: 60px;">用户昵称：</label>
                <div class="controls">
                    <input type="text" class="control-text" name="nickName" id="nickName">
                </div>
            </div>
            <div class="control-group span8" style="width: 220px;">
                <label class="control-label" style="width: 60px;">用户账号：</label>
                <div class="controls">
                    <input type="text" class="control-text" name="account" id="account">
                </div>
            </div>
            <div class="control-group span8" style="width: 220px;">
                <label class="control-label" style="width: 60px;">收货人：</label>
                <div class="controls">
                    <input type="text" class="control-text" name="userName" id="userName">
                </div>
            </div>
         <c:if test="${param.type eq '0'}">
            <div class="control-group span8" style="width: 220px;">
                <label class="control-label" style="width: 60px;">商品名称：</label>
                <div class="controls">
                    <input type="text" class="control-text" name="productName" id="productName">
                </div>
            </div>
         </c:if>
            <div class="control-group span8"  style="width: 220px;">
                <label class="control-label" style="width: 50px;">状态：</label>
                <div class="controls" >
                    <select name="status" id="status" >
                        <option value="">--全部--</option>
                        <option value="Create">待支付</option>
                        <option value="1">已支付</option>
                        <option value="Pay">已支付，待发货</option>
                        <option value="Send">已发货</option>
                        <option value="Fail">支付失败</option>
                        <option value="Close">已关闭</option>
                    </select>
                </div>
            </div>
            <div class="control-group span12" style="width: 400px;">
                <label class="control-label" style="width: 70px;">订单时间：</label>
                <div class="controls">
                    <input type="text" class="calendar calendar-time" id="startDate" name="startDate"><span> - </span><input name="endDate" id="endDate" type="text" class="calendar calendar-time">
                </div>
            </div>
            <input type="hidden" name="type" id="type" value="${param.type}"/>
            <div class="span6 offset2">
                <button  type="button" id="btnSearch" class="button button-primary">搜索</button>
        <c:if test="${param.type eq '0'}">
                <button  type="button"  class="button" onclick="exportData();">发货导出</button>
        </c:if>
            </div>
        </div>
    </form>

    <div class="search-grid-container">
        <div id="grid"></div>
    </div>
</div>
<script type="text/javascript" src="/resources/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="/resources/js/bui-min.js"></script>
<script type="text/javascript" src="/resources/js/config-min.js"></script>
<script type="text/javascript">
    var store,gridCfg;
  BUI.use(['common/search','common/page','bui/grid','bui/overlay','bui/form'],function (Search,Page,Grid,Overlay,Form) {
    var  columns = [
              {title:'订单号',dataIndex:'no',width:130},
              {title:'消费者昵称',dataIndex:'memberAccount',width:100},
              {title:'收货人',dataIndex:'userName',width:80},
                <c:if test="${param.type eq '0'}">
              {title:'商品名称',dataIndex:'productName',width:120,renderer:function(value,obj){
                  return obj.productName +"*"+obj.productId;
              }},
                </c:if>
              {title:'订单状态',dataIndex:'status',width:120,renderer:function(value,obj){
                  if(obj.status=='Create'){
                      return "待支付";
                  }else if(obj.status=='Pay'){
                      return "支付成功,待发货";
                  }else if(obj.status=='Fail'){
                      return "支付失败";
                  }else if(obj.status=='Send'){
                      return "已发货";
                  }else if(obj.status=='Suc'){
                      return "已完成";
                  }else if(obj.status=='Close'){
                      return "已关闭";
                  }
              }},
            {title:'订单金额',dataIndex:'totalMoney',width:80},
            {title:'支付金额',dataIndex:'payAmount',width:80},
            {title:'使用余额',dataIndex:'bonusAmount',width:80},

            {title:'返现总额',dataIndex:'remark',width:80,renderer:function(value,obj){
                return "<a href='javascript:void(0);' onclick=\"showCnt('"+obj.id+"')\">"+obj.remark+"</a>";
            }},
            {title:'订单时间',dataIndex:'dateStr',width:130},
            <c:if test="${param.type eq '0'}">
                {title:'发货时间',dataIndex:'sendDateStr',width:120},
            </c:if>
            {title:'操作',dataIndex:'operate',width:150,renderer:function(value,obj){
                var editStr =  Search.createLink({ //链接使用 此方式
                    id : 'edit' + obj.id,
                    title : '详情',
                    text : '详情',
                    href : '/order/detail?id='+obj.id+"&no="+$("#no").val()+"&account="+$("#account").val()+"&nickName="+$("#nickName").val()+"&userName="+$("#userName").val()+"&status="+$("#status").val()+"&startDate="+$("#startDate").val()+"&endDate="+$("#endDate").val()
                });
                var updateStr = "";
                if(obj.status=='Pay'){
                    updateStr = "<a href=\"javascript:void(0);\" onclick=\"updateStatus('"+obj.id+"','Send')\">发货</a>";
                }else if(obj.status=='Send'){
                   // updateStr = "<a href=\"javascript:void(0);\" onclick=\"updateStatus('"+obj.id+"','Suc')\">完成</a>";
                }else if(obj.status=='Create'){
                    updateStr = "<a href=\"javascript:void(0);\" onclick=\"updateStatus('"+obj.id+"','Close')\">关闭</a>";
                }
                var payStr =  "&nbsp;&nbsp;<a href=\"javascript:void(0);\" onclick=\"updateStatus('"+obj.id+"','Pay')\">支付</a>";
                var delStr =  "&nbsp;&nbsp;<a href=\"javascript:void(0);\" onclick=\"del('"+obj.id+"')\">删除</a>";
                return editStr+updateStr+payStr+delStr;
            }}
            ];
            store = Search.createStore('/order/listData');
            gridCfg = Search.createGridCfg(columns,{
              plugins : [BUI.Grid.Plugins.CheckSelection] // 插件形式引入多选表格
            });
  });
    function updateStatus(id,status){
        var msg = "确定操作？";
        if(status=="Send"){
            msg = "确定发货吗？";
        }else if(status =='Close'){
            msg = "确定关闭吗？";
        }
        BUI.Message.Confirm(msg,function(){
            $.ajax({
                url :"/order/updateStatus",
                type : 'post',
                data : {
                    id:id,
                    status:status
                },
                success : function(data){
                    BUI.Message.Alert(data.msg,function(){
                        if(data.success){ //删除成功
                            top.topManager.reloadPage();
                        }
                    });
                }
            });
        },'question');
    }
    function del(id){
        var msg = "确定删除吗？";
        BUI.Message.Confirm(msg,function(){
            $.ajax({
                url :"/order/delete",
                type : 'post',
                data : {
                    id:id
                },
                success : function(data){
                    BUI.Message.Alert(data.msg,function(){
                        if(data.success){ //删除成功
                            top.topManager.reloadPage();
                        }
                    });
                }
            });
        },'question');
    }
    function exportData(){
        window.location.href = "/order/export?no="+$("#no").val()+"&status="+$("#status").val()+"&startDate="+$("#startDate").val()+"&endDate="+$("#endDate").val()+"&nickName="+$("#nickName").val()+"&account="+$("#account").val()+"&type="+$("#type").val()+"&userName="+$("#userName").val();
        if(confirm("是否将订单置为发货状态？")){
            $.ajax({
                url:"/order/batchSend?r="+Math.random(),
                type:"post",
                data:{
                    no:$("#no").val(),
                    status:$("#status").val(),
                    startDate:$("#startDate").val(),
                    endDate:$("#endDate").val(),
                    nickName:$("#nickName").val(),
                    account:$("#account").val(),
                    type:$("#type").val(),
                    userName:$("#userName").val()
                },
                success:function(res){},
                error:function(){}
            })
        }
    }

    var Overlay = BUI.Overlay
    var dialog = new Overlay.Dialog({
        title:'返现记录',
        width:650,
        height:350,
        contentId:'content',
        success:function () {
            dialog.hide();
        }
    });

    function showCnt(id){
        $.ajax({
            url:"/orderFx/loadDetails?ran="+Math.random(),
            type:"post",
            data:{
                id:id
            },
            success:function(res){
                if(res.success){
                    var html = "";
                    if(res.data!=null&&res.data.length>0){
                        $.each(res.data,function(i,n){
                            html += "<tr  class=\"bui-grid-row bui-grid-row-odd\">";
                            html += "<td class=\"bui-grid-cell grid-td-col1\" style=\"width:100px;\"><div class=\"bui-grid-cell-inner\"><span class=\"bui-grid-cell-text \">"+n.nickName+"</span></div></td>";
                            html += "<td class=\"bui-grid-cell grid-td-col2\" style=\"width:103px;\"><div class=\"bui-grid-cell-inner\"><span class=\"bui-grid-cell-text \">"+n.userName+"</span></div></td>";
                            var type = "";
                            if(n.userType=='Customer'){
                                type = "普通用户";
                            }else if(n.userType=='Gold'){
                                type = "金牌代理";
                            }else if(n.userType=='General'){
                                type = "全国总代";
                            }else if(n.userType=='Partner'){
                                type = "区域合伙人";
                            }
                            html += "<td class=\"bui-grid-cell grid-td-col3\" style=\"width:103px;\"><span class=\"bui-grid-cell-text \">"+type+"</span></div></td>";
                            html += "<td class=\"bui-grid-cell grid-td-col4\" style=\"width:103px;\"><span class=\"bui-grid-cell-text \">"+n.amount+"</span></div></td>";
                            html += "<td class=\"bui-grid-cell grid-td-col5\" style=\"width:120px;\"><span class=\"bui-grid-cell-text \">"+n.dateStr+"</span></div></td>";
                            html += "</tr>";
                        });

                    }else{
                        html  = "<tr><td colspan='5' style=\"align:center;\">暂无记录</td></tr>";
                    }
                    $("#table_info").html(html);
                    dialog.show();
                }
            },
            error:function(){}
        });
    }
</script>
<script type="text/javascript" src="/views/js/list.js"></script>
<div id="content"  style="display:none;">

    <div class="bui-grid bui-simple-list bui-grid-width bui-grid-border bui-grid-strip" style="width: 99%;" aria-disabled="false" aria-pressed="false">
        <div class="bui-grid-header-container">
            <div class="bui-grid-header" style="width: 98%;margin-left:10px;" aria-disabled="false" aria-pressed="false">
                <table cellspacing="0" cellpadding="0" class="bui-grid-table">
                    <thead>
                    <tr>
                        <th class="bui-grid-hd" style="width:100px;" aria-disabled="false" aria-pressed="false">
                            <div class="bui-grid-hd-inner"><span class="bui-grid-hd-title">微信号</span>
                            </div></th>
                        <th class="bui-grid-hd"  style="width:100px;"  aria-disabled="false">
                            <div class="bui-grid-hd-inner"><span class="bui-grid-hd-title">姓名</span></div></th>
                        <th class="bui-grid-hd"  style="width:100px;" aria-disabled="false">
                            <div class="bui-grid-hd-inner"><span class="bui-grid-hd-title">用户级别</span></div></th>
                        <th class="bui-grid-hd"  style="width:100px;" aria-disabled="false">
                            <div class="bui-grid-hd-inner"><span class="bui-grid-hd-title">返现金额</span></div></th>
                        <th class="bui-grid-hd"  style="width:120px;" aria-disabled="false"><div class="bui-grid-hd-inner">
                            <span class="bui-grid-hd-title">返现时间</span></div></th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>


        <div class="bui-grid-body" style="width: 98%;margin-left:10px;">
            <table cellspacing="0" cellpadding="0" class="bui-grid-table" style="width: 98%;">
                <tbody id="table_info">

                </tbody></table>
        </div></div></div></div>
</div>
</body>
</html>  
